<?php
use yii\helpers\Url;
?>
<script src="js/jquery-1.12.3.min.js"></script>
<select name="departmentId" id="departmentId" class="modal-select-sm" onchange="getDepartmentList(this)">
    <option value="0">--部门--</option>
    <?php foreach($departmentsList as $value){

        ?>
        <option value="<?=$value['id']?>" ><?=$value['departName']?></option>

        <?php foreach($value['twoGrade'] as $twoValue){
            ?>
            <option value="<?=$twoValue['id']?>">-<?=$twoValue['departName']?></option>
            <?php
            foreach($twoValue['threeGrade'] as $threeValue){
                ?>
                <option value="<?=$threeValue['id']?>">--<?=$threeValue['departName']?></option>
                <?php
                foreach($threeValue['fourGrade'] as $fourValue){
                    ?>
                    <option value="<?=$fourValue['id']?>">---<?=$fourValue['departName']?></option>
                    <?php
                    foreach($fourValue['fiveGrade'] as $fiveValue){

                        ?>

                        <option value="<?=$fiveValue['id']?>">----<?=$fiveValue['departName']?></option>
                    <?php } ?>
                    <?php
                } ?>
            <?php    } ?>
        <?php } ?>

    <?php } ?>
</select>
<select name="responUserId" id="responUserId" class="modal-select-sm">
    <option value="0">--员工--</option>

</select>
<script>
    function getDepartmentList(object){
        var params={};
        params.departmentId=$(object).val();
        console.log(params);
        var url="<?=Url::toRoute(['system/department-list'])?>";
        $.post(url,params,function(data){
            var data=JSON.parse(data);
            var str='';
           data.forEach(function(v){
               str+='<option value="'+v['id']+'">'+v['userName']+'</option>';
           });
            console.log(str);
            $(object).next().html(str);
        });

    }
</script>